/**
 * Created by loso on 2017/3/9.
 */
public class _121_BestTimeToBuyAndSellStock {
    public static void main(String[] args) {

    }

    public int maxProfit(int[] prices) {
        if (prices.length == 0)
            return 0;
        int max = 0;

        int bought = prices[0];
        for (int i = 0; i < prices.length; i++) {
            if (prices[i]<bought){
                bought = prices[i];
            }
            else{
                if(max<(prices[i]-bought))
                {
                    max=prices[i]-bought;
                }
            }
        }

        return max;

    }


}
